package com.education.teach.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.Button;

import com.education.teach.MainActivity;
import com.education.teach.R;
import com.education.teach.di.component.DaggerLoginComponent;
import com.education.teach.di.module.LoginModule;
import com.education.teach.mvp.contract.LoginContract;
import com.education.teach.mvp.model.bean.LoginBean;
import com.education.teach.mvp.presenter.LoginPresenter;
import com.education.teach.utils.DnCommonUtils;
import com.education.teach.widget.ClearEditText;
import com.jaeger.library.StatusBarUtil;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import dn.easy.common.commonutils.JsonUtils;
import dn.easy.common.commonutils.LogUtils;
import dn.easy.common.commonutils.StringUtils;

import static com.jess.arms.utils.Preconditions.checkNotNull;

// 登录
public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View {

    @BindView(R.id.et_user_name)
    ClearEditText mEtUserName;
    @BindView(R.id.et_password)
    ClearEditText mEtPassword;
    @BindView(R.id.bt_login)
    Button mLogin;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLoginComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .loginModule(new LoginModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mEtUserName.setText("220322197806191203");
        mEtPassword.setText("1");
        mLogin.setOnClickListener(v -> mPresenter.login(mEtUserName.getText().toString(), mEtPassword.getText().toString()));
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.makeText(this, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public void returnLoginResult(LoginBean loginBean) {
        DnCommonUtils.setUserModel(this, loginBean);
        launchActivity(new Intent(this, MainActivity.class));
        finish();
    }
}
